require("../../../lib/bmap-wx.min.js");

var t, a = require("../../../utils/util.js"), e = getApp(), o = [], i = {
    MAX: 18,
    MIN: 5,
    DEFAULT: 12
}, d = e.globalData.url;

Page({
    data: {
        domain: d,
        markers: [],
        hidden: !0,
        latitude: "",
        longitude: "",
        placeData: {},
        isHidden: !0,
        markerLat: [],
        selectShopId: "",
        scale: i.DEFAULT,
        polyline: [ {
            points: o,
            color: "#99FF00",
            width: 4
        } ],
        initialTime: 0,
        currentPlayTime: 0,
        videoContext: null,
        videoIconUrl: "https://www.yanda123.com/yanda/attach/readFile?size=800&id=7837"
    },
    markerclose: function(a) {
        t.setData({
            isHidden: !0
        });
    },
    makertap: function(a) {
        var e = a.markerId;
        o = [];
        for (var i in t.data.markers) t.data.markers[i].id == e && (t.mapCtx.includePoints({
            padding: [ 80 ],
            points: [ {
                latitude: t.data.markers[i].latitude,
                longitude: t.data.markers[i].longitude
            }, {
                latitude: t.data.latitude,
                longitude: t.data.longitude
            } ]
        }), wx.setNavigationBarTitle({
            title: t.data.markers[i].title
        }), o.push({
            latitude: t.data.latitude,
            longitude: t.data.longitude
        }, {
            latitude: t.data.markers[i].latitude,
            longitude: t.data.markers[i].longitude
        }), t.setData({
            polyline: [ {
                points: o,
                color: "#1d82d2",
                width: 4
            } ]
        }), t.showSearchInfo(t.data.markers[i]), t.changeMarkerColor(t.data.markers, e));
    },
    onLoad: function(a) {
        (t = this).getShopInfo(), t.getLocation(), t.getIsOrder(), t.mapCtx = wx.createMapContext("map"), 
        void 0 !== a.id && t.setData({
            selectShopId: a.id
        });
    },
    getLocation: function() {
        var t = this;
        wx.getLocation({
            type: "gcj02",
            success: function(a) {
                t.setData({
                    latitude: a.latitude,
                    longitude: a.longitude
                });
            },
            fail: function(t) {
                wx.showToast({
                    title: "请授权定位，获取门店",
                    icon: "none"
                });
            }
        });
    },
    showSearchInfo: function(a) {
        t.setData({
            isHidden: !1,
            selectLat: a.latitude,
            selectLng: a.longitude,
            selectAddr: a.shopAddr,
            selectShopName: a.title,
            selectShopId: a.id,
            placeData: {
                title: a.title + "\n",
                address: "地址：" + a.shopAddr + "\n"
            }
        });
    },
    changeMarkerColor: function(a, e) {
        var o = [];
        for (var i in a) a[i].id === e ? a[i].iconPath = "/image/auto/icon_02.png" : a[i].iconPath = "/image/auto/icon01.png", 
        o[i] = a[i];
        t.setData({
            markers: o
        });
    },
    mylocation: function() {
        t.setData({
            scale: 16
        }), wx.getLocation({
            type: "gcj02",
            success: function(a) {
                t.setData({
                    latitude: a.latitude,
                    longitude: a.longitude,
                    appAuth: !0,
                    wxAuth: !0
                });
            },
            fail: function(a) {
                t.noAppLocationAuth(a.errMsg) && wx.showModal({
                    title: "定位失败",
                    content: "请到手机系统中打开微信的定位服务",
                    showCancel: !1,
                    confirmText: "知道了"
                }), t.noWxLocationAuth(a.errMsg) && (t.setData({
                    appAuth: !0
                }), wx.showModal({
                    title: "定位失败",
                    content: "请允许小程序使用定位服务",
                    confirmText: "获取"
                }));
            }
        });
    },
    scan: function() {
        var t = e.globalData.token;
        wx.scanCode({
            onlyFromCamera: !0,
            success: function(o) {
                if (void 0 !== o.path) {
                    var i = o.path.lastIndexOf("="), d = o.path.substring(i + 1, o.path.length);
                    a.request(e, "wx/cust/autoWashCanUseShop", "GET", {
                        token: t,
                        shop: d
                    }, function(t) {
                        t.state && (t.data ? wx.navigateTo({
                            url: "../prepares1/index?id=" + d
                        }) : wx.showToast({
                            title: "没有对应门店",
                            icon: "none"
                        }));
                    }, function(t) {});
                }
            }
        });
    },
    getShopInfo: function() {
        var i = [], d = "", n = this.data.markers, r = e.globalData.token;
        a.request(e, "wx/biz/getBizShopsAutoWash", "GET", {
            token: r
        }, function(e) {
            if (e.state) {
                for (var r = 0; r < e.data.length; r++) i.push({
                    id: e.data[r].latitude + "," + e.data[r].longitude + ";"
                });
                for (var s = 0; s < i.length; s++) d += i[s].id;
                d = d.substring(0, d.length - 1), a.transformatLat({
                    locations: d,
                    type: 3,
                    key: "HVLBZ-Q24C2-CO6U2-C3AUW-EH4E6-D3F6X"
                }, function(a) {
                    t.setData({
                        markerLat: t.data.markerLat.concat(a.locations)
                    });
                    for (var i = 0; i < e.data.length; i++) {
                        var d = t.data.markerLat[i].lat, r = t.data.markerLat[i].lng;
                        n.push({
                            id: e.data[i].shopId,
                            latitude: d,
                            longitude: r,
                            title: e.data[i].shopName,
                            shopAddr: e.data[i].shopAddr,
                            iconPath: "/image/auto/icon01.png",
                            width: 50,
                            height: 50,
                            anchor: {
                                x: 0,
                                y: 1
                            },
                            callout: {
                                content: e.data[i].shopName,
                                color: "#ffffff",
                                fontSize: 14,
                                borderRadius: 16,
                                bgColor: "#262930",
                                padding: 8
                            }
                        });
                    }
                    if (t.setData({
                        markers: n
                    }), "" != t.data.selectShopId) {
                        o = [];
                        var s = t.data.selectShopId;
                        for (var l in t.data.markers) t.data.markers[l].id == s && (t.mapCtx.includePoints({
                            padding: [ 80, 50, 50, 50 ],
                            points: [ {
                                latitude: t.data.markers[l].latitude,
                                longitude: t.data.markers[l].longitude
                            }, {
                                latitude: t.data.latitude,
                                longitude: t.data.longitude
                            } ]
                        }), wx.setNavigationBarTitle({
                            title: t.data.markers[l].title
                        }), o.push({
                            latitude: t.data.latitude,
                            longitude: t.data.longitude
                        }, {
                            latitude: t.data.markers[l].latitude,
                            longitude: t.data.markers[l].longitude
                        }), t.setData({
                            polyline: [ {
                                points: o,
                                color: "#1d82d2",
                                width: 4
                            } ]
                        }), t.showSearchInfo(t.data.markers[l]), t.changeMarkerColor(t.data.markers, s));
                        null != t.data.polyline[0].points && "" != t.data.polyline[0].points[0].latitude && "" != t.data.polyline[0].points[1].latitude || t.setData({
                            polyline: [ {
                                points: [],
                                color: "#1d82d2",
                                width: 4
                            } ]
                        });
                    }
                }, function(t) {});
            }
        }, function(t) {});
    },
    introduce: function() {
        wx.navigateTo({
            url: "/pages/autoWash/introduce/index"
        });
    },
    unload: function() {
        t.setData({
            selectShopId: ""
        }), t.setData({
            markers: []
        }), t.getShopInfo(), t.setData({
            polyline: [ {
                points: [],
                color: "#1d82d2",
                width: 4
            } ]
        }), t.setData({
            isHidden: !0
        }), wx.setNavigationBarTitle({
            title: "光速洗车"
        });
    },
    shopNav: function(t) {
        wx.navigateTo({
            url: "/pages/autoWash/shopNav/index?id=" + t.currentTarget.dataset.id + "&lat=" + t.currentTarget.dataset.lat + "&lng=" + t.currentTarget.dataset.lng + "&shopName=" + t.currentTarget.dataset.shopname + "&shopAddr=" + t.currentTarget.dataset.shopaddr + "&click=1"
        });
    },
    videoInfo: function() {
        var o = e.globalData.token;
        a.request(e, "wx/biz/getDataBasePicture", "POST", {
            token: o,
            shopId: t.data.selectShopId
        }, function(a) {
            if (a.state) {
                var e = a.message;
                t.data.catchImg != e ? (t.catchImg(), t.setData({
                    isHidden: !0,
                    hidden: !1
                })) : (t.setData({
                    isHidden: !1,
                    hidden: !0
                }), wx.showToast({
                    title: "请勿多次点击",
                    icon: "none"
                }));
            }
        }, function(t) {});
    },
    unloadVideo: function() {
        t.setData({
            hidden: !0
        }), t.data.isHidden && t.setData({
            isHidden: !1
        });
    },
    getIsOrder: function() {
        var o = e.globalData.token;
        a.request(e, "wx/cust/getUnfinishedOrder", "GET", {
            token: o
        }, function(a) {
            a.state && null != a.data && (t.setData({
                reServiceOrderId: a.data.serviceOrderId,
                reCarNo: a.data.carNo,
                reShopId: a.data.shopId,
                reAddTime: a.data.addTime,
                reShopAddr: a.data.shopAddr
            }), wx.showModal({
                title: "未完成订单",
                content: "您确定要恢复订单吗",
                success: function(a) {
                    a.confirm ? wx.redirectTo({
                        url: "/pages/autoWash/start/start?serviceOrderId=" + t.data.reServiceOrderId + "&shopId=" + t.data.reShopId
                    }) : a.cancel && wx.showToast({
                        title: "取消成功"
                    });
                }
            }));
        }, function(t) {});
    },
    catchImg: function() {
        var o = e.globalData.token;
        a.request(e, "wx/biz/getDataBasePicture", "POST", {
            token: o,
            shopId: t.data.selectShopId
        }, function(a) {
            if (a.state) {
                var e = a.message;
                t.data.catchImg != e && t.setData({
                    catchImg: e
                });
            }
        }, function(t) {});
    }
});